package com.wechatnotice.wechatnotice.utils;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


/**
 * @author Admin
 */
@Component
public class HttpsUtil {

    private final static String URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=";

    public static void main(String[] args) {
        //-------------------get请求-------------------
        //get请求无参
        String getResult = cn.hutool.http.HttpUtil.get(URL);
        Map beanMap = JSONUtil.toBean(getResult, Map.class);

        Map<String, Object> paramMap = new HashMap<>(10);
        paramMap.put("k1","v1");
        //get请求有参
        HttpUtil.get(URL,paramMap);

        //get请求有参并设置超时时间 单位为毫秒
        HttpUtil.get(URL,paramMap,30000);

        //-------------------post请求-------------------
        //post请求无参
        //形参:
        //urlString – 网址
        //body – post表单数据
        HttpUtil.post(URL, "");

        //post请求有参
        HttpUtil.post(URL,paramMap);

        //post请求有参并设置超时时间 单位为毫秒
        HttpUtil.post(URL,paramMap,30000);

    }

}
